﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.AspNetCore.Structs
{
    public class ModelConfigManager
    {
        private static List<ModelConfig> entityConfigs = new List<ModelConfig>();

        public static List<ModelConfig> ModelConfigs
        {
            get { return entityConfigs; }
        }

        public static ModelConfig GetModelConfig(string name)
        {
            return ModelConfigs.FirstOrDefault(t => string.Compare(t.Name, name, true) == 0);
        }

        public static void AddModelConfig(ModelConfig modelConfig)
        {
            if (string.IsNullOrEmpty(modelConfig.Name))
            {
                return;
            }

            var old = ModelConfigs.FirstOrDefault(t => string.Compare(t.Name, modelConfig.Name, true) == 0);
            if (old != null)
            {
                ModelConfigs.Remove(old);
            }

            ModelConfigs.Add(modelConfig);
        }
    }
}
